﻿<?php
// ------------------------------------------------------------------
// NEEDED STUBS FOR THIS EXAMPLE
// ------------------------------------------------------------------


// this will include all needed files to be able to build a Request
include_once($CONF["STUBS_FOLDER"]."Map24Routing/Map24Routing.php5");


// ------------------------------------------------------------------
// NEEDED PARAMETERS FOR THIS REQUEST
// ------------------------------------------------------------------


// RouteID (from last calculated route)
$RouteID		 = $_COOKIE['RouteID'];

// Set true, to Load Traffic Infos
$LoadTMCs	 	 = true;

// Set true, to ignore waypoints
$IgnoreWaypoints = true;

// definition of the properties

//Set the Coordinates Style
$proIdx=0;
$property[$proIdx]= new Property();
$property[$proIdx]->Key= 'CoordinatesStyle';
$property[$proIdx]->Value= 'MAP';


// Check first, if there is a RouteID, because we need one
if(isset($RouteID) ) {

	// ------------------------------------------------------------------
	// BUILDING THE REQUEST
	// ------------------------------------------------------------------


	// definition of the request header with Map24ID and SessionID
	$header = new RequestHeader();
	$header->Map24ID  = $CONF['MAP24_ID'];
	$header->ClientID = $CONF['SESSION_ID'];


	// definition of the request body
	$request = new FetchRouteRequest();
	$request->RouteID = $RouteID;
	$request->LoadTMCs = $LoadTMCs;
	$request->IgnoreWaypoints = $IgnoreWaypoints;
	$request->Properties = $Property;


	// ------------------------------------------------------------------
	// EXECUTE THE REQUEST
	// ------------------------------------------------------------------


	// in this object the SoapClient will be initiated and executed
	$routing = new Map24Routing($CONF['MAPTP_SYSTEM'],$CONF['MAP24_ID'],$CONF['SESSION_ID']);
	$response = $routing->FetchRoute($header,$request);


	// ------------------------------------------------------------------
	// OUTPUT THE RESULT
	// ------------------------------------------------------------------


	$resultString = "Your RouteID was: " . $RouteID . "<p>";
	$counter = 0;

	if( isset($response->Route) )
	{
		foreach ($response->Route->Segments as $result)
		{
			$counter++;
			$resultString .= "<div style='border:1px solid black;margin:2px 0px;padding:5px;'>".$counter.". ";
			foreach ( $result->Descriptions as $description )
			{
				$resultString .= $description->Text."<br /><br />";
			}
			$resultString .= "</div>";
		}
	}
	else
	{
		$resultString = "Sorry, no answer from the Webservices =(";
	}
}
// throw an error message, if there is no routeID
else {
	$resultString = "Please calculate first a route!";
}

?>